package com.amkai.mobile.client.appointmentdetails;

import com.amkai.mobile.bean.scheduler.appointment.MobileAppointmentDetails;
import com.amkai.mobile.client.R;
import com.amkai.mobile.client.common.AEMobileConstants;
import com.amkai.mobile.common.job.scheduler.MobileSchedulerJob;
import com.amkai.mobile.common.job.scheduler.MobileSchedulerJobResult;
import com.amkai.mobile.utils.manager.job.MobileServiceManager;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 
 * @author lkovari
 *
 */
public class AppointmentTabPM extends Activity {
	private TextView timeRangeTextView = null;
	private TextView apptTypeValueTextView = null;
	private TextView apptStatusTextView = null;
	private TextView apptTypeColorTextView = null;
	private TextView targetLabelTextView = null;
	private TextView targetValueTextView = null;
	private TextView referringTextView = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        setContentView(R.layout.appointmenttabpm);

        // capture ids
        Bundle bundle = getIntent().getExtras();
        Long beId = bundle.getLong(AEMobileConstants.BUNDLE_CONTENT_TAG_DEPARTMENTID);
        Long passId = bundle.getLong(AEMobileConstants.BUNDLE_CONTENT_TAG_PASSPORTID);
        Long apptId = bundle.getLong(AEMobileConstants.BUNDLE_CONTENT_TAG_APPOINTMENTID);
        
        // download appointmentTetails
		try {
			MobileSchedulerJobResult schedulerResult = MobileServiceManager.processMobileJob(AppointmentTabPM.this, MobileSchedulerJob.appointmentDetailsById(apptId));
			if (schedulerResult.getException() == null) {
				MobileAppointmentDetails mobileAppointmentDetails = schedulerResult.getMobileAppointmentDetails();
				showAppointmentDetails(mobileAppointmentDetails);
			}
			else {
				Toast msg = Toast.makeText(AppointmentTabPM.this, "Download appointment data failed!", Toast.LENGTH_SHORT);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void showAppointmentDetails(MobileAppointmentDetails appointmentDetails) {
        timeRangeTextView = (TextView) findViewById(R.id.timeValueTextView);
        timeRangeTextView.setText(appointmentDetails.beginTime + " - " + appointmentDetails.endTime);

    	apptStatusTextView = (TextView) findViewById(R.id.statusValueTextView);
    	apptStatusTextView.setText(appointmentDetails.status);
        
//        apptTypeColorTextView = (TextView) findViewById(R.id.apptTypeColorTextView);
//        apptTypeColorTextView.setBackgroundColor(appointmentDetails.mobileAppointmentType.color);
        
        apptTypeValueTextView = (TextView) findViewById(R.id.apptTypeValueTextView);
        apptTypeValueTextView.setText(appointmentDetails.mobileAppointmentType.name);
        apptTypeValueTextView.setTextColor(appointmentDetails.mobileAppointmentType.color);
        
        targetLabelTextView = (TextView) findViewById(R.id.targetLabelTextView);
        targetValueTextView = (TextView) findViewById(R.id.targetValueTextView);
        referringTextView = (TextView) findViewById(R.id.referValueTextView);
        if (!appointmentDetails.isSCorSH) {
        	targetLabelTextView.setText("Provider");
        	targetValueTextView.setText(appointmentDetails.mobileSchedulerTarget.name);
        	if (appointmentDetails.referring != null)
        		referringTextView.setText(appointmentDetails.referring.name);
        }
        
	}
}
